package com.zsyh.changshang.ui;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;


import com.zsyh.changshang.MainActivity;
import com.zsyh.changshang.R;
import com.zsyh.changshang.basic.BaseActivity;
import com.zsyh.changshang.basic.StatusUtil;
import com.zsyh.changshang.basic.Viewable;
import com.zsyh.changshang.basic.qidongpresenter;
import com.zsyh.changshang.contract.QidongyeContract;
import com.zsyh.changshang.util.EmptyUtil;
import com.zsyh.changshang.util.SPUtils;

import butterknife.BindView;
import butterknife.OnClick;


@Viewable(presenter = qidongpresenter.class, layout = R.layout.qidonglayoit)
public class QidongyeActivity extends BaseActivity<QidongyeContract.View, QidongyeContract.Presenter> implements QidongyeContract.View {


    @BindView(R.id.tv_read_time)
    TextView tvReadTime;

    private int time=3;
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            time--;
                tvReadTime.setText("跳过"+time+"s");


            if (time==0){
                tvReadTime.setText("跳过"+0+"s");
                gettonoqidong();
                handler.removeMessages(0);
            }
            handler.sendEmptyMessageDelayed(0,1000);
        }
    };

    @Override
    public void init() {

        StatusUtil.setUseStatusBarColor(this, 0x00ffffff);
        StatusUtil.setSystemStatus(this, false, true);


        handler.sendEmptyMessageDelayed(0,1000);

    }



    @OnClick(R.id.tv_read_time)
    public void onViewClicked() {
        gettonoqidong();
    }


    public void gettonoqidong() {
        if (EmptyUtil.isEmpty((String) SPUtils.get(this, "token", ""))) {
            Intent intent = new Intent(this, LoginActivity.class);
            startActivity(intent);
            tvReadTime.setText("");
            this.finish();
        } else {
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            tvReadTime.setText("");
            this.finish();
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }
}
